<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<html>
<head>
<title></title>
<link href="<s:url value='/common/lib/ligerUI/skins/Aqua/css/ligerui-all.css'/>" rel="stylesheet" type="text/css" />
<link href="<s:url value='/common/lib/uploadify/uploadify.css'/>" rel="stylesheet" type="text/css" />
<script src="<s:url value='/common/lib/jquery/jquery-1.7.1.min.js'/>" type="text/javascript"></script>
<script src="<s:url value='/common/lib/uploadify/jquery.uploadify.min.js'/>" type="text/javascript"></script>
<script src="<s:url value='/common/lib/ligerUI/js/core/base.js'/>" type="text/javascript"></script>
<script src="<s:url value='/common/lib/ligerUI/js/plugins/ligerDialog.js'/>" type="text/javascript"></script>
<style type="text/css">
	body { 
		font-family: "微软雅黑", "宋体", Arial, sans-serif; 
		font-size: 12px; 
	}
	#upload-box { padding: 10px; }
	.btn { 
		background-color:#FFF; 
		border:1px solid #CDCDCD;
		height:22px; 
		width:70px; 
	}
	.btn1 { 
		background-color:#FFF; 
		border:1px solid #CDCDCD;
		height:22px; 
		width:120px; 
	}
	#gallery {
		padding: 10px;
		height: 700px;
	}
</style>
</head>
<body>
	<s:hidden name="uTimeStamp"/>
	<s:hidden name="uToken"/>
	<s:hidden name="dealerCode"/>
	<s:hidden name="timeStamp"/>
	<s:hidden name="provedType"/>
	<h3>上传证明材料</h3>
	<div id="dealer-code" style="padding: 5px;">
		<div>
			<label style="width: 158px; height: 20px;">请首先输入经销商网络代码:</label>
			<input type="text" id="dealerCodeText" name="dealerCodeText" class="l-text"/>
			<input type="button" id="dealerCodeInput" onclick="inputDealerCode()" value="输入" class="btn"/>
		</div>
		<div style="padding:2px;">
			<label id="stroragePathLabel" style="width: 158px; height: 20px;">请选择原始数据上传日期：</label>
			<select id="stroragePath" style="width: 120px; height: 20px;"></select>
		</div>
	</div>
	
	<div id="imgTypeBox" style="padding:2px;">
		<label id="typeLabel" style="width: 158px; height: 20px; padding:2px;">请选择证明材料类型：</label>
		<input type="radio" value="1" name="imgType" onclick="chooseType()">系统外</input>
		<input type="radio" value="2" name="imgType" onclick="chooseType()">虚拟未查到</input>
		<input type="radio" value="3" name="imgType" onclick="chooseType()">状态二</input>
		<input type="radio" value="0" name="imgType" onclick="chooseType()">其它</input>
	</div>
	
	<div id="upload-box">
		<div id="queue"></div>
		<p><input id="vinImageFile" name="vinImageFile" type="file" /></p>
		<p>
			<a href=""></a>
			<input type="button" class="btn1" value="上传" onclick="sendImage()"/> 
		</p>
	</div>

	<script type="text/javascript">
		var count = 0;
		$(function() {
			var dealerCode = $("#dealerCode").val();
			var timeStamp = $("#timeStamp").val();
			if(dealerCode != "" && timeStamp != "") {
				$("#dealer-code").hide();
				$("#upload-box").hide();
				$("#imgTypeBox").show();
			} else {
				$("#imgTypeBox").hide();
				$("#upload-box").hide();
				$("#stroragePathLabel").hide();
				$("#stroragePath").hide();
				$("#dealerCodeText").focus();
			}
		});
		
		function inputDealerCode() {
			$.post("<s:url value='/record/validDealerCode.action'/>",{dealerCode : $("#dealerCodeText").val()}, function(data) {
				if(data != 0) {
					$.ligerDialog.alert('您输入的经销商网代码有误，请重新输入!', '提示', 'error');
					$("#dealerCodeText").val("");
					$("#dealerCodeText").focus();
				} else {
					var dc = $("#dealerCodeText").val();
					$.post("<s:url value='/record/getStroragePaths.action'/>",{dealerCode : dc}, function(data) {
                		var datas = data.split(":");
                		if(datas[0] == 0) {
                			$("#dealerCodeText").attr("disabled", "disabled");
        					$("#dealerCodeInput").attr("disabled", "disabled");
        					$("#stroragePathLabel").show();
        					$("#stroragePath").show();
                			$("#stroragePath").prepend("<option value='0'>请选择...</option>");
                			var dirs = datas[1].split(",");
                			for(var i = 0; i < dirs.length; i++) {
                				var dir = dirs[i].replace(/\n/g, "").replace(/\r/g, "");
                				$("#stroragePath").append("<option value='" + dir + "'>" + dir + "</option>");
                			}
                			$("#stroragePath").change(function(){
            					var val = $("#stroragePath").val();
            					if(val != 0) {
            						$("#dealerCode").val(dc);
									$("#timeStamp").val(val);
									$("#imgTypeBox").show();
            					}
            				});
                		} else {
                			$.ligerDialog.alert('该经销商尚未上传数据!', '提示', 'none'); 
                		}
                	});
				}
			});
		}
		
		function chooseType() {
			var type = $("input[name='imgType']:checked").val();
			if(type) {
				$("#provedType").val(type);
				$("#upload-box").show();
				showUploadify();
			}
		}
		
		function sendImage() {
			var type = $("#provedType").val();
			var typeTip = "其它";
			if(type == 1) {
				typeTip = "系统外";
			} else if(type == 2) {
				typeTip = "虚拟未查到";
			} else if(type == 3) {
				typeTip = "状态二";
			}
			$.ligerDialog.confirm('您要上传的证明文件类型是：' + typeTip, function (yes) {
				if(yes) {
					$('#vinImageFile').uploadify('upload','*');
				}
			});
		}
		
		function showUploadify() {
			$('#vinImageFile').uploadify({
				'formData'     : {
					'uTimeStamp' : $("#uTimeStamp").val(),
					'uToken'     : $("#uToken").val(),
					'dealerCode' : $("#dealerCode").val(),
					'timeStamp'  : $("#timeStamp").val(),
					'provedType'	 : $("#provedType").val()
				},
				'auto' : false,
				'fileSizeLimit':'100MB',
				'buttonText' : '请选择证明文件',
				'fileTypeDesc' : '证明文件',
		        'fileTypeExts' : '*.*',
				'swf'      : "<s:url value='/common/lib/uploadify/uploadify.swf'/>",
				'uploader' : "<s:url value='/uploadProvedData.action'/>",
				'fileObjName':'provedData',
		        'onQueueComplete' : function(queueData) {
		            $.ligerDialog.alert('您一共上传了' + queueData.uploadsSuccessful + '份证明文件', '提示', 'success');
		        },
		        'onFallback' : function() {
		            alert('没有安装Flash插件,请安装Flash插件，然后重启浏览器');
		        }
			});
		}
	</script>
</body>
</html>